import 'dart:convert' show json;

T asT<T>(dynamic value) {
  if (value is T) {
    return value;
  }
  return null;
}

class LoginEntity {
  LoginEntity({
    this.phone,
    this.realName,
    this.token,
    this.userId,
    this.user_name,
  });

  factory LoginEntity.fromJson(Map<String, dynamic> jsonRes) => jsonRes == null
      ? null
      : LoginEntity(
          phone: asT<String>(jsonRes['phone']),
          realName: asT<String>(jsonRes['realName']),
          token: asT<String>(jsonRes['token']),
          userId: asT<int>(jsonRes['userId']),
          user_name: asT<String>(jsonRes['user_name']),
        );

  String phone;
  String realName;
  String token;
  int userId;
  String user_name;

  Map<String, dynamic> toJson() => <String, dynamic>{
        'phone': phone,
        'realName': realName,
        'token': token,
        'userId': userId,
        'user_name': user_name,
      };

  @override
  String toString() {
    return json.encode(this);
  }
}
